package com.yisoo.rs.rsfile.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.yisoo.rs.common.vo.MovieJsonVo;
import com.yisoo.rs.rsfile.feign.MoiveFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.yisoo.rs.rsfile.entity.DictEntity;
import com.yisoo.rs.rsfile.service.DictService;
import com.yisoo.rs.common.utils.PageUtils;
import com.yisoo.rs.common.utils.R;



/**
 * 
 *
 * @author mmciel
 * @email 761998179@qq.com
 * @date 2021-11-30 15:15:27
 */
@RestController
@RequestMapping("rsfile/dict")
public class DictController {
    @Autowired
    private DictService dictService;

    @Autowired
    private MoiveFeignService moiveFeignService;

//    快速导入/rsfile/dict/quick_import'
    @RequestMapping("/quick_import")
    public R quickImport(@RequestParam("appName")String appName, @RequestParam("fileId")Integer fileId){
//        System.out.println(appName);
//        System.out.println(fileId);
        //抽取出所有的子json，构成list，然后发送给另一个服务，需要创建完整的VO
        List<MovieJsonVo> movieJsonVoList  = dictService.GeneratorMovieList(fileId);
        if (movieJsonVoList.size() == 0){
            return R.error("file_id异常");
        }
        R feignRes = moiveFeignService.quickImport(appName,movieJsonVoList);
        System.out.println(feignRes);
        return feignRes;
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = dictService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{dictId}")
    public R info(@PathVariable("dictId") Long dictId){
		DictEntity dict = dictService.getById(dictId);

        return R.ok().put("dict", dict);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody DictEntity dict){
		dictService.save(dict);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody DictEntity dict){
		dictService.updateById(dict);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] dictIds){
		dictService.removeByIds(Arrays.asList(dictIds));
        return R.ok();
    }

}
